package com.jinxin.platform.cdcardpassmgr.controller;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdcardpassmgr.bean.CdcardpassmgrDevice;
import com.jinxin.platform.cdcardpassmgr.rpc.CdcardpassmgrRpc;
import com.jinxin.platform.cdcardpassmgr.service.ICardpassmgrDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-07-06
 * @Author: Lingnan
 **/
@RestController
@RequestMapping("/cardpassmgrDevice")
@Slf4j
public class CardpassmgrDeviceController {
    @Autowired
    private ICardpassmgrDeviceService deviceService;
    @Autowired
    private CdcardpassmgrRpc cdcardpassmgrRpc;

    @RequestMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,String nickName,
                                   String configStatus){
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("nickName", nickName);
        Integer status = StringUtils.isEmpty(configStatus) ? null : Integer.parseInt(configStatus);
        param.put("configStatus", status);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","");
        resultMap.put("count", deviceService.listPageCount(param));
        resultMap.put("data", deviceService.listPage(param));
        return resultMap;
    }

    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CdcardpassmgrDevice device){
        return deviceService.saveOrUpdate(device);
    }

    @GetMapping("/delete")
    public JsonResult delete(String id){
        return deviceService.delete(id);
    }

    @PostMapping("/syncData")
    public JsonResult syncDeviceData(){
        return cdcardpassmgrRpc.syncDeviceData();
    }

}
